package com.LA_houseLease.admin.controller.login;



import com.LA_houseLease.admin.service.LoginService;
import com.LA_houseLease.admin.vo.login.CaptchaVo;
import com.LA_houseLease.admin.vo.login.LoginVo;
import com.LA_houseLease.admin.vo.system.user.SystemUserInfoVo;
import com.LA_houseLease.common.context.BaseContext;
import com.LA_houseLease.common.properties.JwtProperties;
import com.LA_houseLease.common.result.Result;
import com.LA_houseLease.common.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@CrossOrigin(origins = "*")
@Slf4j
@Tag(name = "后台管理系统登录管理")
@RestController
@RequestMapping("/admin")
public class LoginController {

    @Autowired
    private LoginService loginService;
    @Autowired
    private JwtProperties jwtProperties;

    @Operation(summary = "获取图形验证码")
    @GetMapping("login/captcha")
    public Result<CaptchaVo> getCaptcha() {
        log.warn("获取图形验证码--LoginController.getCaptcha");
        CaptchaVo captchaVo=loginService.getCaptcha();
        return Result.ok(captchaVo);
    }

    @Operation(summary = "登录")
    @PostMapping("login")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        log.warn("登录--LoginController.login");
        String jwt=loginService.login(loginVo);
        return Result.ok(jwt);
    }

    @Operation(summary = "获取登陆用户个人信息")
    @GetMapping("info")
    public Result<SystemUserInfoVo> info() {
        log.warn("获取登陆用户个人信息--LoginController.info");
        Long userId = BaseContext.getLoginUser().getUserId();
        SystemUserInfoVo systemUserInfoVo=loginService.getSystemUserInfoVoByUserId(userId);
        return Result.ok(systemUserInfoVo);
    }
}



















